package com.sl.mes.app.controller;

import com.sl.mes.app.dao.agg.AggDefdoc;
import com.sl.mes.core.util.ResponseUtil;
import com.sl.mes.db.itf.bd.IBdDefdoc;
import com.sl.mes.db.itf.bd.IBdDefdoclist;
import com.sl.mes.db.itf.bd.IBdMaterial;
import com.sl.mes.db.itf.bd.IBdWk;
import com.sl.mes.db.vo.BdDefdoc;
import com.sl.mes.db.vo.BdDefdoclist;
import com.sl.mes.db.vo.BdMaterial;
import com.sl.mes.db.vo.BdWk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mes/def")
@Validated
public class MesDefDocController {

    private static final Logger logger = LoggerFactory.getLogger(MesAuthController.class);

    @Autowired
    private IBdDefdoclist iBdDefdoclist;
    @Autowired
    private IBdDefdoc iBdDefdoc;
    @Autowired
    private IBdMaterial iBdMaterial;
    @Autowired
    private IBdWk iBdWk;

    /**
     * 自定义档案
     * @param code
     * @return
     */
    @GetMapping("/queryDefDoc")
    public Object queryDefDoc(String code, String code1, String code2,String code3,String vwkcode){

        Map<Object,Object>  result = new HashMap<>();
        BdDefdoclist bdDefdoclist = null;
        BdDefdoclist bdDefdoclist1 = null;
        BdDefdoclist bdDefdoclist2 = null;
        BdMaterial bdMaterial=null;
        BdWk bdWk=null;
        try {
            bdDefdoclist = iBdDefdoclist.findByCode(code);
            bdDefdoclist1 = iBdDefdoclist.findByCode(code1);
            bdDefdoclist2 = iBdDefdoclist.findByCode(code2);
            bdMaterial= iBdMaterial.findByCode(code3);
            bdWk=iBdWk.findByVwkcode(vwkcode);
            if (bdWk==null){
               return ResponseUtil.fail(-1,"没有此炉台信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<BdDefdoc> lstbdDefdoc = iBdDefdoc.queryBypkDefdoclist(bdDefdoclist.getPkDefdoclist());
        List<BdDefdoc> lstbdDefdoc1 = iBdDefdoc.queryBypkDefdoclist(bdDefdoclist1.getPkDefdoclist());
        List<BdDefdoc> lstbdDefdoc2 = iBdDefdoc.queryBypkDefdoclist(bdDefdoclist2.getPkDefdoclist());

        AggDefdoc aggDefdoc=new AggDefdoc();
        aggDefdoc.setBdMaterial(bdMaterial);
        aggDefdoc.setBdDefdocLst1(lstbdDefdoc);
        aggDefdoc.setBdDefdocLst2(lstbdDefdoc1);
        aggDefdoc.setBdDefdocLst3(lstbdDefdoc2);
        aggDefdoc.setBdWk(bdWk);
        result.put("aggDefdoc",aggDefdoc);
        return ResponseUtil.ok(aggDefdoc);
    }


}
